import env from './env';
let plugins = [];
if (process.env.NODE_ENV === 'production') {
	plugins.push("transform-remove-console")
}
let config = {
	accessKey: 'ACCESS_KEY',
	sign: 'SIGN'
}
export default {
	// 服务器端变量映射到客户端
	env: {
		NODE_ENV: process.env.NODE_ENV,
		config: config
	},
	// Global page headers: https://go.nuxtjs.dev/config-head
	head: {
		title: 'nuxt',
		htmlAttrs: {
			lang: 'en'
		},
		meta: [{
				charset: 'utf-8'
			},
			/*优先使用 IE 最新版本和 Chrome*/
			{
				"http-equiv": "X-UA-Compatible",
				content: "IE=edge,chrome=1"
			},
			{
				name: 'viewport',
				content: 'initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width,height=device-height'
			},
			{
				hid: "keywords",
				name: "keywords",
				content: 'PCHi'
			},
			{
				hid: 'description',
				name: 'description',
				content: 'nuxt'
			},
			{
				name: 'format-detection',
				content: 'telephone=no'
			},
		],
		link: [{
			rel: 'icon',
			type: 'image/x-icon',
			href: '/favicon.ico'
		}, ],
		script: [{
				src: '/qrcode.min.js'
			},
			{
				src: '/hue.global.js'
			}
		]
	},

	// Global CSS: https://go.nuxtjs.dev/config-css
	css: [{
			src: 'element-ui/lib/theme-chalk/index.css'
		},
		{
			src: '~/assets/styles/styles.scss',
			lang: 'scss'
		},

		{
			src: '~/assets/styles/animate.css'
		},
		{
			src: '~/static/share.min.css'
		},
	],

	// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
	plugins: [{
			src: '~plugins/element-ui'
		},
		{
			src: '~plugins/axios'
		},
		{
			src: '~plugins/common'
		},
		{
			src: '~mixins/seo'
		},
		{
			src: "~/plugins/swiper",
			ssr: false
		},
		{
			src: '~/plugins/wow',
			ssr: false
		},
		{
			src: '~/plugins/share',
			ssr: false
		},
		{
			src: "~/plugins/baidu-map",
			ssr: false
		},
		{
			src: "~/plugins/dict",
			ssr: true
		},
		{
			src: "~/plugins/i18n",
			ssr: true
		},
		 { src: '~/plugins/wx.js', ssr: false },
	],

	// Auto import components: https://go.nuxtjs.dev/config-components
	components: true,

	// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
	buildModules: [
		'@nuxtjs/style-resources',
	],
	styleResources: {
		scss: [
			'~/assets/styles/vars.scss',
			'~/assets/styles/base-funs.scss',
		],
		hoistUseStatements: true
	},

	// Modules: https://go.nuxtjs.dev/config-modules
	modules: [
		"@nuxtjs/axios", "@nuxtjs/proxy", "cookie-universal-nuxt","@nuxtjs/dayjs"
	],
	/*
	 ** axios proxy
	 */
	axios: {
		proxy: true,
		//最多重发0次
		retry: {
			retries: 0
		},
		prefix: '/cmsApi', // baseURL
		//是否是可信任
		withCredentials: true,
		//跨域请求是否需要使用凭证
		credentials: true,
		headers: {
			//'Content-Type': 'application/json',
			'crossDomain': true,
			"Access-Control-Allow-Origin": "*"
		},
		timeout: 15000
	},
	/*
	 ** proxy
	 */
	proxy: {
		'/cmsApi': {
			target: env[process.env.NODE_ENV].ENV_API, // 代理地址
			changeOrigin: true, //是否跨域
			secure: false, //关闭证书签名验证
		}
	},
	/*
	 ** Customize the progress bar color
	 */
	loading: {
		color: '#3B8070',
		height: "2px"
	},

	// Build Configuration: https://go.nuxtjs.dev/config-build
	build: {
		// 分析打包数据使用，平时不用 2021年11月01日14:14:06
		// analyze: true,
		// assetFilter: function (assetFilename) { 
		//   return assetFilename.endswith('.js')
		// },
		// 分析打包数据 end
		// vendor: ["axios"], // 为防止重复打包
		// extractCSS: {
		// 	allChunks: true
		// },
		extractCSS:true,
		optimization: {
			splitChunks: {
				cacheGroups: {
					styles: {
						name: 'styles',
						test: /\.(css|vue)$/,
						chunks: 'all',
						enforce: true
					}
				}
			}
		},
		loaders: {
			less: {
				javascriptEnabled: true,
			}
		},
		babel: {
			plugins
		},
		postcss: null
	},
	router: {
		middleware: ["device", "i18n"],
		extendRoutes(routes, resolve) {
			// 在这里进行路由扩展
			// routes 是当前的路由配置
			// resolve 是 nuxt 用于获取路由组件所定义的方法
			routes.push({
				path: '/node/*',
				redirect: '/page/*',
			})
		}
	}
}